﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Enterprise.ClientWeb.ErrorDocs
{
    public partial class _04 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SiteLinks.Text = string.Format("<ul>{0}</ul>", LoadTree(SiteMap.RootNode.ChildNodes));
        }

        private string LoadTree(SiteMapNodeCollection nodes)
        {
            string o = string.Empty;
            foreach (SiteMapNode node in nodes)
            {
                if (node.Key != null)
                {
                    o += string.Format("<li><a href='/{0}'>{1}</a>", ConstructUrl(node.Title), node.Title);

                    if(node.HasChildNodes)
                        o += string.Format("<ul>{0}</ul>", LoadTree(node.ChildNodes));

                    o += "</li>";
                }
            }
            return o;
        }
        
        private string ConstructUrl(string s)
        {
            return string.Format("{0}.aspx",s);
        }
    } 
}
